{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{if !empty($data)}修改{else}添加{/if}科目</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="add_cate" id="add_know" method="post" action="">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="name" type="text" class="form-control" name="name" value="{$data.name|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">logo：</label>
                            <div class="controls uploadrow2" data-max="1" title="点击修改图片" rel="p_cover">
                                <input type="hidden" name="logo" id="cover_id_p_cover" value="{$data.logo|default=''}" data-callback="uploadImgCallback" value=""/>
                                <div class="upload-img-box" rel="img"  {if empty($data['logo'])} style="display:none" {/if} >
                                <div class="upload-pre-item2">
                                    <img width="100" height="100" src="{$data.logo|default=''}"/>
                                </div>
                                <em class="edit_img_icon">&nbsp;</em>
                            </div>
                        </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">说明：</label>
                    <div class="input-group col-sm-4">
                        <input id="remark" type="text" class="form-control" name="remark" value="{$data.remark|default=''}">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-3">
                        <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                        <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                    </div>
                </div>
                </form>
            </div>
        </div>

    </div>
</div>
</div>
{include file="public/footer" /}

<script type="text/javascript">

    $(function(){

        //初始化上传图片插件
        initUploadImg();
    });

    function uploadImgCallback(name,id,src){

        $('#cover_id_p_cover').val(src);
    }

    $(function(){
        $('#add_know').ajaxForm({
            beforeSubmit: checkForm,
            success: complete,
            dataType: 'json'
        });

        function checkForm(){
            if( '' == $.trim($('#name').val())){
                layer.msg('请输入名称',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }else if( '' == $.trim($('#remark').val())){
                    layer.msg('请输入说明',{icon:2,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
            }
        }

        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('Knowledge/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;
            }
        }

    });
</script>

<script type="text/javascript">

</script>
</body>
</html>